package com.tzz.service.impl;

import com.tzz.dao.StationDao;
import com.tzz.entity.Station;
import com.tzz.exception.AddExistException;
import com.tzz.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class StationServiceImpl implements StationService {
    @Autowired
    StationDao stationDao;

    @Override
    public List<Station> findStationsByNameId(Station station) {
        return stationDao.getStationByNameCode(station);
    }

    @Override
    public void addStation(Station station) throws AddExistException {
        if(stationDao.getStationByNameCode(station).size() > 0){
            throw new AddExistException("新增站点信息已存在");
        }
        stationDao.insertStation(station);
    }

    @Override
    public void changeStationStaus(Integer id) {
        stationDao.updateStationStatus(id);
    }

}
